package org.agile4j.plugin.gun.utils;

import java.util.Map;

import org.apache.commons.collections4.map.HashedMap;

/**
 * 替换字段容器工具类
 * 
 * @author hanyx
 *
 */
public class ReplaceContainerUtil {

	private static final ThreadLocal<Map<String, String>> REPLACE_HOLDER =  new ThreadLocal<Map<String, String>>() {
		protected Map<String,String> initialValue() {
			return new HashedMap<String, String>() ;
		};
	};

	public static void setContainerHolder(Map<String, String> map) {
		REPLACE_HOLDER.set(map);
	}
	
	public static Map<String, String> getReplaceMap() {
		return REPLACE_HOLDER.get() ;
	}
	
	public static void init() {
		REPLACE_HOLDER.set(new HashedMap<String, String>());
	}
	
	public static void destory() {
		REPLACE_HOLDER.remove();
	}
	
	public static void remove(String key) {
		getReplaceMap().remove(key) ;
	}
	
	public static boolean containsKey(String key) {
		return getReplaceMap().containsKey(key) ;
	}
	
	public static String getReplaceValue(String key) {
		return getReplaceMap().get(key) ;
	}
	
	public static void putRepalceValue(String key, String value) {
		getReplaceMap().put(key, value) ;
	}
	
}
